﻿Public Class WinnerState
    Implements IState
    Private _machine As GumballMachine

    Public Sub New(ByVal machine As GumballMachine)
        _machine = machine
    End Sub

    Public Sub dispense() Implements IState.dispense
        Console.WriteLine("YOU'RE A WINNER! You get two gumballs for your quarter")
        Try
            _machine.ReleaseBall()
            If _machine.Count = 0 Then
                _machine.CurrentState = _machine.SoldOutState
            Else
                _machine.ReleaseBall()
                If _machine.Count > 0 Then
                    _machine.CurrentState = _machine.NoQuarterState
                Else
                    Console.WriteLine("Oops, out of gumballs!")
                    _machine.CurrentState = _machine.SoldOutState
                End If
            End If
        Catch ex As Exception
            Console.WriteLine(ex.StackTrace)
        End Try
    End Sub

    Public Sub ejectQuarter() Implements IState.ejectQuarter
        Console.WriteLine("Please wait, we're already giving you a Gumball")
    End Sub

    Public Sub insertQuarter() Implements IState.insertQuarter
        Console.WriteLine("Please wait, we're already giving you a Gumball")
    End Sub

    Public Sub turnCrank() Implements IState.turnCrank
        Console.WriteLine("Turning again doesn't get you another gumball!")
    End Sub

    Public Overrides Function ToString() As String
        Return "dispensing two gumballs for your quarter, because YOU'RE A WINNER!"
    End Function
End Class
